<%@page contentType="text/html" %>
<%@page pageEncoding="UTF-8" %>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j" %>
<%@taglib prefix="rich" uri="http://richfaces.org/rich" %>
<%@ taglib prefix="t" uri="http://myfaces.apache.org/tomahawk" %>


<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Goodwill - Отчет о балансе и остатках</title>
    <link rel="stylesheet" href="resources/css/main.css"/>
    <link rel="stylesheet" href="resources/css/stylesheet.css"/>
    <link rel="stylesheet" type="text/css" href="resources/css/jquery.countdown.css">
    <script type="text/javascript">
        function reloadPage() {
            window.location.reload();
        }
    </script>
</head>
<body>
<f:view>
    <jsp:include page="menu.jsp"/>
    <jsp:include page="status.jsp"/>
    <h:form id="balanceReportForm" styleClass="full">
        <h:outputText value="Фильтр: " styleClass="b"/>
        <h:panelGroup layout="block" styleClass="filter_subpanel">
            <h:outputText value="Группа товара"/>
            <h:selectOneMenu value="#{SessionBean.goodsFilter.goodTypeId}" styleClass="f_s" style="margin-left: 10px">
                <f:selectItems value="#{GoodTypesBean.goodTypesAsSelectItems}"/>
            </h:selectOneMenu>
            <h:outputText value="Показывать только заканчивающиеся позиции " style="margin-left: 10px"/>
            <h:selectBooleanCheckbox value="#{SessionBean.goodsFilter.onlyDispose}" style="margin-left: 10px"/>
            <h:outputText value="Только с комментариями " style="margin-left: 10px"/>
            <h:selectBooleanCheckbox value="#{SessionBean.goodsFilter.onlyWithComments}" style="margin-left: 10px"/>
        </h:panelGroup>
        <a4j:commandButton reRender="reportsTable" value="Применить" action="#{GoodsBean.applyFilter}"
                           style="margin-left: 10px"/>
        <a4j:commandButton id="AllRowsButton" value="#{BalanseReportBean.allRows?'Постраничный режим':'Все данные'}"
                           action="#{BalanseReportBean.showAllRows}" reRender="balanceReportForm"
                           style="margin-left: 10px"
                           status="none"/>
        <h:outputLink value="TopProductsReport.jsf">
            <h:outputText value="ТОП 100" style="margin-left: 10px"/>
        </h:outputLink>
        <rich:dataTable id="reportsTable"
                                value="#{BalanseReportBean.goods}"
                                var="good"
                                rowKeyVar="row"
                                rows="#{BalanseReportBean.rowsCount}"
                                border="2" styleClass="full"
                                rendered="true"
                                style="margin-top: 10px"
                >
            <rich:column
                    width="5%">
                <a4j:commandLink id="editLink"
                                 ajaxSingle="true"
                                 onclick="Richfaces.showModalPanel('SetCriteria')"
                                 status="none">
                    <h:graphicImage value="resources/img/edit.gif"/>
                    <f:setPropertyActionListener value="#{good}" target="#{BalanseReportBean.good}"/>
                </a4j:commandLink>
                <rich:toolTip for="editLink" value="Редактировать"/>
                <a4j:commandLink id="salesLink"
                                 ajaxSingle="true"
                                 onclick="Richfaces.showModalPanel('ShowSales')"
                                 status="none">
                    <h:graphicImage value="resources/img/personal_price_16.png"/>
                    <f:setPropertyActionListener value="#{good}" target="#{BalanseReportBean.good}"/>
                </a4j:commandLink>
                <rich:toolTip for="salesLink" value="См. продажи"/>
            </rich:column>
            <rich:column sortable="true"
                         sortBy="#{good.code}"
                         filterBy="#{good.code}"
                         filterEvent="onblur"
                         width="10%"
                         styleClass="#{good.dangerousRest==0?'zero':good.count - good.reservedCount<good.dangerousRest?'little':''}">
                <f:facet name="header">
                    <h:outputText value="Код"/>
                </f:facet>
                <h:outputText value="#{good.code}"/>
            </rich:column>
            <rich:column width="20%"
                         styleClass="#{good.dangerousRest==0?'zero':good.count - good.reservedCount<good.dangerousRest?'little':''}">
                <f:facet name="header">
                    <h:outputText value="Применимость"/>
                </f:facet>
                <h:outputText value="#{good.prShort}"/>
            </rich:column>
            <rich:column width="10%"
                         styleClass="#{good.dangerousRest==0?'zero':good.count - good.reservedCount<good.dangerousRest?'little':''}">
                <f:facet name="header">
                    <h:outputText value="Доступно"/>
                </f:facet>
                <h:outputText value="#{(good.count - good.reservedCount) <= 0? 0 : good.count - good.reservedCount}"/>
            </rich:column>
            <rich:column id="criteria" width="10%"
                         styleClass="#{good.dangerousRest==0?'zero':good.count - good.reservedCount<good.dangerousRest?'little':''}">
                <f:facet name="header">
                    <h:outputText value="Критерий"/>
                </f:facet>
                <h:outputText value="#{good.dangerousRest}"/>
            </rich:column>
            <rich:column width="65%"
                         styleClass="#{good.dangerousRest==0?'zero':good.count - good.reservedCount<good.dangerousRest?'little':''}">
                <f:facet name="header">
                    <h:outputText value="Коментарий"/>
                </f:facet>
                <h:outputText value="#{good.coment}"/>
            </rich:column>
            <f:facet name="footer">
                <rich:datascroller id="datascroller"/>
            </f:facet>
        </rich:dataTable>
    </h:form>
    <rich:modalPanel id="SetCriteria" autosized="true" width="400">
        <f:facet name="header">
            <a4j:outputPanel ajaxRendered="true">
                <h:outputText value="Введите новые значения для #{BalanseReportBean.good.code}"/>
            </a4j:outputPanel>
        </f:facet>
        <h:form>
            <a4j:outputPanel ajaxRendered="true">
                <h:panelGrid columns="2">
                    <h:outputText value="Критерий " style="margin-right: 10px"/>
                    <h:inputText value="#{BalanseReportBean.good.dangerousRest}" style="margin-left: 10px"/>
                </h:panelGrid>
                <h:panelGrid columns="1">
                    <h:outputText value="Комментарий "/>
                    <rich:editor width="350" value="#{BalanseReportBean.good.coment}" styleClass="full"/>
                </h:panelGrid>
                <h:panelGrid columns="1">
                    <h:outputText value="#{BalanseReportBean.good.salesForMonth}"/>
                </h:panelGrid>
            </a4j:outputPanel>
            <h:panelGrid columns="2" styleClass="full" columnClasses="butLeft,butRight">
                <a4j:commandButton value="Сохранить" action="#{BalanseReportBean.setNewDangerousRest}"
                                   oncomplete="Richfaces.hideModalPanel('SetCriteria')"
                                   reRender="balanceReportForm"
                                   />
                <a4j:commandButton value="Отменить"
                                   action="#{BalanseReportBean.clearAll}"
                                   onclick="Richfaces.hideModalPanel('SetCriteria')"
                                   status="none"/>
            </h:panelGrid>
        </h:form>
    </rich:modalPanel>
    <rich:modalPanel id="ShowSales" autosized="true" width="400">
        <f:facet name="header">
            <a4j:outputPanel ajaxRendered="true">
                <h:outputText value="Динамика продаж для #{BalanseReportBean.good.code}"/>
            </a4j:outputPanel>
        </f:facet>
        <h:form>
            <a4j:outputPanel ajaxRendered="true">
                <h:panelGrid columns="4">
                    <h:outputText value="1 мес."/>
                    <h:outputText value="3 мес." style="margin-left: 30px"/>
                    <h:outputText value="6 мес." style="margin-left: 30px"/>
                    <h:outputText value="Год" style="margin-left: 30px"/>
                    <h:outputText value="#{BalanseReportBean.salesForMonth}"/>
                    <h:outputText value="#{BalanseReportBean.salesForThreeMonths}" style="margin-left: 30px"/>
                    <h:outputText value="#{BalanseReportBean.salesForSixMonths}" style="margin-left: 30px"/>
                    <h:outputText value="#{BalanseReportBean.salesForYear}" style="margin-left: 30px"/>
                </h:panelGrid>
            </a4j:outputPanel>
            <a4j:commandButton value="Отменить" action="#{BalanseReportBean.clearAll}"
                               onclick="Richfaces.hideModalPanel('ShowSales')" status="none"/>
        </h:form>
    </rich:modalPanel>

</f:view>
</body>
</html>